﻿Imports System.Configuration

Namespace DAL

    Friend Class DbConfig

        ''' <summary>
        ''' Get Connection String from App.Config based on the given ContextName
        ''' </summary>
        ''' <param name="contextName">Context Name</param>
        ''' <returns>Connection String, otherwise null/Nothing if it failed to retrieve based on the given contextName</returns>
        ''' <remarks></remarks>
        Friend Shared Function GetConnectionString(ByVal contextName As String) As String
            Dim connectionString As String = Nothing

            Try
                connectionString = ConfigurationManager.ConnectionStrings(contextName).ConnectionString
                Debug.Assert(connectionString <> Nothing, String.Format("There is no such context named {0}", contextName))
            Catch exception As ConfigurationErrorsException
                Console.WriteLine(exception.Message)
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try

            Return connectionString
        End Function

    End Class

End Namespace
